﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>ImagesUpload</title>
    <link href="~/layui/css/layui.css" rel="stylesheet" />
    <link href="~/layuimini/css/public.css" rel="stylesheet" />
    <link href="~/layuimini/lib/jq-module/zyupload/zyupload-1.0.0.min.css" rel="stylesheet" />
    <style>
        .layui-btn-container {
            font-size: 15px;
        }
    </style>
</head>
<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <form class="layui-form layui-form-pane" action="">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">项目名称</label>
                        <div class="layui-input-inline">
                            <input type="text" id="ProjectName" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>


            </form>
        </div>
        <div class="layui-btn-container">
            <button type="button" class="layui-btn layui-btn-normal" id="test8">选择文件</button>
            <button type="button" class="layui-btn" id="test9">开始上传</button>
        </div>
    </div>
    <script src="~/layuimini/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
    <script src="~/layui/layui.js"></script>
    <script type="text/javascript">
            layui.use(['upload', 'element', 'layer','form'], function () {
                var $ = layui.jquery
                , upload = layui.upload
                , element = layui.element
                , form=layui.form
                , layer = layui.layer;



                var uploadInst=upload.render({
                    elem: '#test8'
                 , url: "/default/UploadFile" //改成您自己的上传接口
                 , auto: false
                 , accept: 'file'
                 , acceptMime: 'application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
                 , exts: 'xls|xlsx'// 上传文件的类型
                 , fileSize: 1024000    // 上传文件的大小
                 , data: { ProjectName: $('#ProjectName').val() }
                    //,multiple: true
                 , bindAction: '#test9'
                 , done: function (res) {
                     if (res.Code == 0) {
                         layer.msg('成功', { icon: 6, time: 2000 },
                                           function () {
                                               var index = parent.layer.getFrameIndex(window.name);
                                               parent.layer.close(index);
                                           });
                     }
                     else {
                         layer.alert(res.Message, { icon: 5 });
                     }

                     console.log(res)
                 }
                });
                // 初始化插件
                //选完文件后不自动上传
                form.on('select(brickType)', function (data) {
                    uploadInst.reload({
                        data: { ProjectName: $('#ProjectName').val() },
                    });
                });
                $("#ProjectName").on("change", function (e) {
                    uploadInst.reload({
                        data: { ProjectName: e.delegateTarget.value },
                    });
                   //alert(e.delegateTarget.value);
                });
            });
    </script>
</body>
</html>
